import ob from './funPromise' ;

// const successCode = ['20']

const partialRequest = (pram) => ob.request(pram).then(res=>{
  let {data} = res ,
      code = data.code
  switch(code){
    case 200 :
      console.log('请求成功' + pram.url)
      return Promise.resolve(res.data) ;
    default:
      console.log('请求失败' + pram.url)
      return Promise.reject(res) ;
  }
  // res.statusCode
  
})
// .catch(err=>)

const request = (pram)=>partialRequest(pram)

const requestGet = (pram)=>partialRequest(Object.assign(pram,{method:'GET'}))
const requestPost = (pram)=>partialRequest(Object.assign(pram,{method:'POST'}))

export {
  request ,
  requestGet ,
  requestPost 
}
